package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ruoyi.system.domain.UserInfo;
import com.ruoyi.system.service.IUserInfoService;

@RestController
@RequestMapping("/userInfo")
public class UserInfoController extends BaseController {
    @Autowired
    private IUserInfoService userInfoService;

    /**
     * 微信登录接口
     * @param loginCode 微信登录code
     * @return 登录结果
     */
    @GetMapping("/login")
    public AjaxResult login(@RequestParam String loginCode) {
        // 调用微信API获取openid和session_key
        // 这里需要实现微信API的调用逻辑

        // 模拟返回数据
        UserInfo userInfo = userInfoService.loginByWeChat(loginCode);

        return AjaxResult.success("操作成功", userInfo);
    }

    /**
     * 获取用户详细信息
     */
    @GetMapping("/getUserInfo")
    public AjaxResult getUserInfo(@RequestParam String userId) {
        UserInfo userInfo = userInfoService.selectUserInfoByUserId(userId);
        return AjaxResult.success(userInfo != null ? userInfo : new UserInfo());
    }


    @PostMapping("/updateUserInfo")
    public AjaxResult updateUserInfo(@RequestBody UserInfo userInfo) {
        return toAjax(userInfoService.updateUserInfo(userInfo));
    }
}